﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Steamrunner
{
    class EffectManager : GameComponent
    {
        SpriteSheetManager spritesheetManager = null;
        SpriteBatch spriteBatch = null;

        public EffectManager(Game game, SpriteBatch spritebatch, SpriteSheetManager spritesheetmanager)
            : base(game)
        {
            spriteBatch = spritebatch;
            spritesheetManager = spritesheetmanager;
        }

        public override void Initialize()
        {
            SpriteSheet spritesheet = new SpriteSheet(Game, "Images\\Effects\\FallingEffect", new Vector2(0f, 0f), new Point(64, 64), Point.Zero, new Point(4, 1), 40, spriteBatch);
            spritesheet.Initialize();
            spritesheetManager.AddSpriteSheet("FallingEffect", spritesheet);

            spritesheet = new SpriteSheet(Game, "Images\\Effects\\LeftFallingEffect", new Vector2(64f, 0f), new Point(64, 64), Point.Zero, new Point(4, 1), 40, spriteBatch);
            spritesheet.Initialize();
            spritesheetManager.AddSpriteSheet("LeftFallingEffect", spritesheet);

            spritesheet = new SpriteSheet(Game, "Images\\Effects\\JumpEffect", new Vector2(32f, 64f), new Point(64, 128), Point.Zero, new Point(4, 1), 40, spriteBatch);
            spritesheet.Initialize();
            spritesheetManager.AddSpriteSheet("JumpEffect", spritesheet);

            spritesheet = new SpriteSheet(Game, "Images\\Effects\\LeftJumpEffect", new Vector2(10f, 64f), new Point(64, 128), Point.Zero, new Point(4, 1), 40, spriteBatch);
            spritesheet.Initialize();
            spritesheetManager.AddSpriteSheet("LeftJumpEffect", spritesheet);

            spritesheet = new SpriteSheet(Game, "Images\\Effects\\RunningEffect", new Vector2(64f, 0f), new Point(64, 32), Point.Zero, new Point(4, 1), 40, spriteBatch);
            spritesheet.Initialize();
            spritesheetManager.AddSpriteSheet("RunningEffect", spritesheet);

            spritesheet = new SpriteSheet(Game, "Images\\Effects\\RunningEffectCopper", new Vector2(64f, 0f), new Point(64, 32), Point.Zero, new Point(4, 1), 40, spriteBatch);
            spritesheet.Initialize();
            spritesheetManager.AddSpriteSheet("RunningEffectCopper", spritesheet);

            spritesheet = new SpriteSheet(Game, "Images\\Effects\\SlideEffect", new Vector2(96f, 32f), new Point(160, 64), Point.Zero, new Point(4, 1), 40, spriteBatch);
            spritesheet.Initialize();
            spritesheetManager.AddSpriteSheet("SlideEffect", spritesheet);

            spritesheet = new SpriteSheet(Game, "Images\\Effects\\FallDamageEffect", new Vector2(64f, 0f), new Point(128, 32), Point.Zero, new Point(4, 1), 40, spriteBatch);
            spritesheet.Initialize();
            spritesheetManager.AddSpriteSheet("FallDamageEffect", spritesheet);

            //spritesheet = new SpriteSheet(Game, "Images\\Effects\\WallInpactEffect", new Vector2(32f, 32f), new Point(64, 64), Point.Zero, new Point(1, 1), 40, spriteBatch);
            //spritesheet.Initialize();
            //spritesheetManager.AddSpriteSheet("WallInpactEffect", spritesheet);

            spritesheet = new SpriteSheet(Game, "Images\\Effects\\WallSlidingEffect", new Vector2(0f, 45f), new Point(64, 96), Point.Zero, new Point(5, 1), 40, spriteBatch);
            spritesheet.Initialize();
            spritesheetManager.AddSpriteSheet("WallHuggingEffect", spritesheet);

            spritesheet = new SpriteSheet(Game, "Images\\Effects\\LeftWallSlidingEffect", new Vector2(64f, 45f), new Point(64, 96), Point.Zero, new Point(5, 1), 40, spriteBatch);
            spritesheet.Initialize();
            spritesheetManager.AddSpriteSheet("LeftWallHuggingEffect", spritesheet);

            base.Initialize();
        }

        public void UpdateEffect(string id, GameTime gameTime)
        {
            spritesheetManager.UpdateSpriteSheet(id, gameTime);
        }

        public void DrawEffect(string id, GameTime gameTime, Vector2 position)
        {
            spritesheetManager.DrawSpriteSheet(id, gameTime, position, 0f);
        }

        public void FlushEffect(string id)
        {
            spritesheetManager.FlushSpriteSheet(id);
        }
    }
}
